<?php

require_once('./discuz_publish.php');

$base_url = "http://blog.sina.com.cn/s/blog_466c66400100bi2j.html";
$i = 0;
while($base_url)
{
	$content = file_get_contents($base_url);

	$content = substr($content, stripos($content, 'class="titName SG_txta">') + strlen('class="titName SG_txta">'));
	$title = substr($content, 0, stripos($content, '</h2>'));
	echo $title . "\t";

	$content = substr($content, stripos($content, 'class="articalContent  ">') + strlen('class="articalContent  ">'));
	$cont = substr($content, 0, stripos($content, '<!-- 正文结束 -->'));
	$content = substr($content, stripos($content, 'sans-serif;">') + strlen('sans-serif;">'));
	
	if(empty($title)) break;

	file_put_contents( dirname(__FILE__ ) . '/log', $title . '{br}'. $cont . '{br}');
	//str_replace()
	discuz_publish(escape_s($title), escape_s($cont), 86);
	
	$content = substr($content, stripos($content, '<span class="SG_txtb">后一篇&nbsp;&gt;</span>')+strlen('<span class="SG_txtb">后一篇&nbsp;&gt;</span>'));
	$next = substr($content, 0, stripos($content, '</a></div>'));
	$next = trim($next, '<a href=');
	$next = trim($next, '"');
	$next = explode('">', $next);

	//if(stripos($next[1], 'nginx') !== false)
	{
		$base_url = $next[0];
	}
	//else
	{
	//	break;
	}
	$i++;
	if($i >= 30) break;
}

function escape_s($content)
{
	$content = str_replace( "'", "\'", $content);
	$content = str_replace('"', '\"', $content);
	$content = str_replace('<br />', '', $content);
	$content = preg_replace('/<div.*?>/i', '', $content);
	$content = preg_replace('/<\/div>/i', '', $content);
	return $content;
}
//var_dump($next);




?>